<template>
  <div class="floating-cart" @click="goToCart" v-if="cartItemCount > 0">
    <div class="cart-icon">
      <el-icon size="24"><ShoppingCart /></el-icon>
      <span class="cart-badge">{{ cartItemCount }}</span>
    </div>
    <div class="cart-text">购物车</div>
  </div>
</template>

<script>
import { computed } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { ShoppingCart } from '@element-plus/icons-vue'

export default {
  name: 'FloatingCart',
  components: {
    ShoppingCart
  },
  setup() {
    const store = useStore()
    const router = useRouter()

    const cartItemCount = computed(() => store.getters.cartItemCount)

    const goToCart = () => {
      router.push('/cart')
    }

    return {
      cartItemCount,
      goToCart
    }
  }
}
</script>

<style scoped>
.floating-cart {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: linear-gradient(135deg, #64b5f6 0%, #42a5f5 100%);
  color: white;
  border-radius: 50px;
  padding: 12px 20px;
  box-shadow: 0 8px 25px rgba(100, 181, 246, 0.4);
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.floating-cart:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 35px rgba(100, 181, 246, 0.6);
}

.cart-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ff4757;
  color: white;
  border-radius: 50%;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  border: 2px solid white;
}

.cart-text {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .floating-cart {
    bottom: 20px;
    right: 20px;
    padding: 10px 15px;
  }
  
  .cart-text {
    display: none;
  }
}
</style> 